import unittest
from ddt import ddt,file_data
import requests

@ddt
class dy(unittest.TestCase):
    host='http://10.59.9.18/'
    def setUp(self) -> None:
        print('测试用例开始')
    def tearDown(self) -> None:
        print('测试用例结束')
    #登录
    #http://10.59.9.18/movieApi/user/v2/login
    userId=None
    sessionId=None
    @file_data('./dy.json')
    def test_01_login(self,email,pwd):
        url=dy.host+'movieApi/user/v2/login'
        param={"email":email,"pwd":pwd}
        login=requests.post(url=url,params=param)
        print(login.json())
        dy.userId=str(login.json()['result']['userId'])
        print(dy.userId)
        dy.sessionId=login.json()['result']['sessionId']
        print(dy.sessionId)
    #查询热门电影列表
    #http://172.17.8.100/movieApi/movie/v2/findHotMovieList
    movieId=None
    def test_02_findHotMovieList(self):
        url=dy.host+'movieApi/movie/v2/findHotMovieList'
        param={"page":"2","count":"5"}
        findHotMovieList=requests.get(url=url,params=param)
        print(findHotMovieList.json())
        dy.movieId=findHotMovieList.json()['result'][0]['movieId']
        print(dy.movieId)
    #添加用户对影片的评论
    #http://172.17.8.100/movieApi/movie/v1/verify/movieComment
    def test_03_movieComment(self):
        url=dy.host+'movieApi/movie/v1/verify/movieComment'
        header={"userId":dy.userId,"sessionId":dy.sessionId}
        param={"movieId":dy.movieId,"commentContent":"电影好看","score":"4.5"}
        movieComment=requests.post(url=url,headers=header,json=param)
        print(movieComment.json())

if __name__=='__main__':
    unittest.main()

